﻿
@inject IHttpService _httpService
@inject IPageModelCatche<List<LatestCommentItemModel>> _pageModelCatche
@inject NavigationManager NavigationManager

<CnGalWebSite.Components.Containers.MiniModeContainer>
    <section class="latast-comments-card">
        <h2>近期留言</h2>
        <div class="group">
            @foreach (var item in _items.Take(6))
            {
                <MDCard Class="item" Href="@item.Url">
                    <img class="user-image" src="@item.UserImage" alt="@item.UserName" loading="lazy" />
                    <div class="content">
                        <div class="name">@item.UserName</div>
                        <div class="text">
                            <CnGalWebSite.Shared.MasaComponent.Shared.Components.Markdown.MarkdownViewTip Text="@item.Content" IsNeedHighlight="false" />
                        </div>
                        <div class="time  label-large">@item.Time</div>
                    </div>
                </MDCard>
            }
        </div>
    </section>
</CnGalWebSite.Components.Containers.MiniModeContainer>


@code {

    List<LatestCommentItemModel> _items { get; set; } = new List<LatestCommentItemModel>();

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }


    protected override async Task OnInitializedAsync()
    {
        try
        {
            _items = await _pageModelCatche.GetCache("api/home/ListLatestComments");
            StateHasChanged();
        }
        catch (Exception ex)
        {
            await ErrorHandler.ProcessError(ex, "获取主页公告列表失败");
        }
    }
}
